<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>正则使用场景</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    <input type="password" class="ipt">

    <script type="text/javascript">
        var ipt = document.querySelector(".ipt");

        ipt.onchange = function (){
            console.log(this.value);
            var val = this.value;
            if(val.length < 6){
                alert("密码长度必须大于6");
            }else if(/[^a-z]/i.test(val)){
                alert("密码必须全是英文字母");
            }
        }
    </script>
</body>
</html>